<template>
  <a-layout>
    <a-row type="flex" class="topline">
      <a-icon type="left" style="font-size:20px;position" @click="goback" />
      <div class="left2" style="cursor:pointer;" @click="goback">返回</div>
      <h3>{{ pageTitle }}</h3>
      <a-icon type="add" />
    </a-row>
    <a-layout-content class="stepbox">
      <a-steps :current="current">
        <a-step title="编辑公告" />
        <a-step title="预览发布" />
      </a-steps>
      <EditNew
        v-show="current === 1"
        :notice-title.sync="noticeTitle"
        :notice-file-list.sync="noticeFileList"
        :notice-time.sync="noticeTimeString"
        :notice-content.sync="noticeContent"
        :notice-content-has-style.sync="noticeContentHasStyle"
        :notice-file-list-init="noticeFileList"
        :notice-title-init="noticeTitle"
        :notice-time-init="noticeTime"
        :notice-content-init="noticeContentHasStyle"
        @current="stepModulechange"
      />
      <PreviewNew
        v-show="current === 2"
        :news-type-id="newsTypeId"
        :notice-title="noticeTitle"
        :notice-file-list.sync="noticeFileList"
        :group-code="groupCode"
        :notice-time="noticeTimeString"
        :notice-content="noticeContent"
        :notice-content-has-style="noticeContentHasStyle"
        :notice-content-init-sync="noticeContentHasStyle"
        :notice-title-init-sync="noticeTitle"
        @current="stepModulechange"
      />
    </a-layout-content>
  </a-layout>
</template>
<script>
import { getNewDetail } from "@/api/company/news";
import editNew from "./components/editNew";
import previewNew from "./components/previewNew";

export default {
  components: {
    EditNew: editNew,
    PreviewNew: previewNew
  },
  data() {
    return {
      pushDate: undefined,
      pageTitle: "新建",
      isActive: -1,
      current: 1,
      currentNew: null,
      companyId: "",
      noticeTitle: "",
      noticeFileList: [],
      groupCode: null,
      noticeTime: undefined,
      noticeContent: "",
      noticeContentHasStyle: "",
      noticeTitleInit: "",
      noticeContentHasStyleInit: "",
      newsTypeId: "",
      noticeTimeString: undefined
    };
  },
  mounted() {
    this.companyId = this.$store.state.hr.companyId;
    this.groupCode = this.$route.query.groupCode;
    this.newsTypeId = this.$route.query.id;
    if (this.$route.query.state === "edit") {
      this.pageTitle = "编辑";
      this.getDetail(this.newsTypeId);
    } else {
      this.pageTitle = "新建";
    }
  },
  methods: {
    getDetail(newsTypeId) {
      getNewDetail({ newsTypeId: newsTypeId }).then(res => {
        this.currentNew = res.data;
        this.noticeTitle = this.currentNew.title;
        this.pushDate = this.currentNew.pushDate;
        this.noticeFileList = this.currentNew.newsFileListVO;
        this.noticeContentHasStyle = this.currentNew.contentHasStyle;
        this.noticeTime = this.currentNew.pushDate;
        this.noticeTimeString = this.currentNew.pushDate + "";
      });
    },
    goback() {
      this.$router.go(-1);
    },
    nextStep() {
      this.current = 1;
    },
    stepModulechange(e) {
      this.current = e;
    }
  }
};
</script>
<style lang="scss">
.left2 {
  z-index: 3;
  left: 50px;
  position: absolute;
  color: #595959;
  font-size: 16px;
}
</style>
